﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Xml.Linq;

namespace Twi.COMMON.WPF
{
    [ValueConversion(typeof(string), typeof(string))]
    public class DateTimeConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.ToString().Trim() == "")
            {
                return "";
            }

            if (parameter.ToString() == "date") 
            {
                return DateTime.Parse(value.ToString()).ToString("yyyy-MM-dd");
            }
            else if (parameter.ToString() == "shortdate")
            {
                return DateTime.Parse(value.ToString()).ToString("yyyy-MM");
            }
            else if (parameter.ToString() == "datetime") 
            {
                return DateTime.Parse(value.ToString()).ToString("yyyy-MM-dd HH:mm");
            }
            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }

        #endregion
    }
}
